//
//  SimilarSingerViewController.m
//  Coco_Music
//
//  Created by dlios on 15-6-26.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SimilarSingerViewController.h"

@interface SimilarSingerViewController ()

@end

@implementation SimilarSingerViewController
-(void)dealloc
{
    [_myTabView release];
    [_myArray release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor= [UIColor yellowColor];
    
self.myTabView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStyleGrouped];
    
    self.myTabView.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:self.myTabView];
    self.myTabView.separatorStyle = UITableViewCellSeparatorStyleNone;
 
    self.myTabView.delegate = self;
    self.myTabView.dataSource =self;
    
    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"正在加载,请稍后";
    [self.HUD show:YES];
    
    
}
#define SimilarConnect @"http://api.dongting.com/sim/singer/%ld/similarity?"
#define SimilarConnect1 @"app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"

-(void)setSongID:(NSInteger)SongID
{
   
    
    NSString *url =[NSString stringWithFormat:SimilarConnect,(long)SongID];
    NSString *url1 =[NSString stringWithFormat:url,SimilarConnect1];
    [AFN_block NSString:url1 Blokc:^(id request) {
        NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary:request];
        NSLog(@"相似歌手 %@",dic);
        
          self.myArray =[NSMutableArray array];
        NSMutableArray *dataArray =[dic objectForKey:@"data"];
        
        for (NSMutableDictionary *myDic in dataArray) {
            similarSinger *SimilarSinger =[[similarSinger alloc]init];
            SimilarSinger.singer_id =[[myDic objectForKey:@"singerId"]integerValue];
            SimilarSinger.SingerName =[myDic objectForKey:@"name"];
            SimilarSinger.picUrl =[myDic objectForKey:@"picUrl"];
            SimilarSinger.albumsCount =[[myDic objectForKey:@"albumsCount"]integerValue];
            SimilarSinger.songsCount =[[myDic objectForKey:@"songsCount"]integerValue];
            SimilarSinger.chineseName =[myDic objectForKey:@"chineseName"];
            SimilarSinger.englishName =[myDic objectForKey:@"englishName"];
            
            [self.myArray addObject:SimilarSinger];
            
                }
     [self.myTabView reloadData];
        [self.HUD hide:YES];
        

    }];



}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier =@"cell";
    SimilarViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[SimilarViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    }
    cell.SimilarSinger = [self.myArray objectAtIndex:indexPath.row];
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
    
    }];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.myTabView deselectRowAtIndexPath:indexPath animated:YES];
    similarSinger *abc = [[similarSinger alloc] init];
  
    [self.myTabView deselectRowAtIndexPath:indexPath animated:YES];
    abc = [self.myArray objectAtIndex:indexPath.row];
    [self.myDelegate ChangeID:abc.singer_id];
    [self setSongID:abc.singer_id];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.
    }
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
